﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex04.Menus.Delegates
{
    public class MenuAction : IMenuItem
    {
        private string m_DisplayText;

        /// <summary>
        /// An event that is fired when an item is chosen.
        /// </summary>
        public event EventHandler ItemChosen;

        public MenuAction(string i_DisplayText)
        {
            m_DisplayText = i_DisplayText;
        }

        public string DisplayText
        {
            get { return m_DisplayText; }
        }

        /// <summary>
        /// Selects the item.
        /// </summary>
        public void Select()
        {
            Console.Clear();
            OnItemChosen();
        }

        protected virtual void OnItemChosen()
        {
            if (ItemChosen != null)
            {
                ItemChosen.Invoke(this, new EventArgs());
            }
        }
    }
}